$file=$ARGV[0];
$outfile=$ARGV[1];
chomp($file);
chomp($outfile);
open(BUFF,"$file") or die " no file $file found\n";
while(<BUFF>)
{
	chomp($_);
	@array=split(" ",$_);
	$pos{$array[3]}=1;
	$chr=$array[0];
}
if($chr ==23)
{
	$ref="/data4/bsi/refdata/genetics/1000Genomes/downloaded_data/release/20110521/impute/ALL_1000G_phase1integrated_feb2012_impute/ALL_1000G_phase1integrated_feb2012_chrX_nonPAR_impute.legend.gz";
}
else
{
	$ref="/data4/bsi/refdata/genetics/1000Genomes/downloaded_data/release/20110521/impute/ALL_1000G_phase1integrated_feb2012_impute/ALL_1000G_phase1integrated_feb2012_chr".$chr."_impute.legend.gz";
}
if(!(-e $ref))
{
	die " file $ref not exists\n";
}
open(BUFF,"gunzip -c $ref|") or die " no file exists $ref\n";
$line=<BUFF>;
while(<BUFF>)
{
	chomp($_);
	@array=split(" ",$_);
	if(exists($pos{$array[1]}))
	{
		#print "$array[0] $array[1] $array[9] \n";
		if($array[9] < 0.15)
		{
			$selected{$array[1]} =1;
		}
	}
}
open(BUFF,"$file") or die " no file $file found\n";
open(WRBUFF,">$outfile") or die "not able to write $file\n";
while(<BUFF>)
{
	chomp($_);
	@array=split(" ",$_);
	if(exists($selected{$array[3]}))
	{
		print WRBUFF $_."\n";
	}
}
